home *** CD-ROM | disk | FTP | other *** search
/ User's Choice Windows CD / User's Choice Windows CD (CMS Software)(1993).iso / win_u_z / vlistsam.zip / LISTTEST.C < prev    next >
C/C++ Source or Header  |  1992-09-01  |  12KB  |  355 lines

  1. #include "listtest.h"
  2.  
  3. HINSTANCE    hVlbLib;
  4.  
  5. int PASCAL WinMain(HANDLE hInstance, HANDLE hPrevInstance, LPSTR lpszCmdLine, int nCmdShow)
  6. {
  7.  MSG        msg;           /* MSG structure to store your messages        */
  8.  int        nRc;           /* return value from Register Classes          */
  9.  
  10.  strcpy(szAppName, "LISTTEST");
  11.  hInst = hInstance;
  12.  
  13.  if(!hPrevInstance)
  14.    {
  15.     /* register window classes if first instance of application         */
  16.     if ((nRc = nCwRegisterClasses()) == -1)
  17.       {
  18.        /* registering one of the windows failed                         */
  19.        LoadString(hInst, IDS_ERR_REGISTER_CLASS, szString, sizeof(szString));
  20.        MessageBox(NULL, szString, NULL, MB_ICONEXCLAMATION);
  21.        return nRc;
  22.       }
  23.    }
  24.  
  25.  /* create application's Main window                                    */
  26.  hWndMain = CreateWindow(
  27.                 szAppName,               /* Window class name           */
  28.                 NULL,                   /* no title                     */
  29.                 WS_CAPTION      |        /* Title and Min/Max           */
  30.                 WS_SYSMENU      |        /* Add system menu box         */
  31.                 WS_MINIMIZEBOX  |        /* Add minimize box            */
  32.                 WS_MAXIMIZEBOX  |        /* Add maximize box            */
  33.                 WS_THICKFRAME   |        /* thick sizeable frame        */
  34.                 WS_CLIPCHILDREN |         /* don't draw in child windows areas */
  35.                 WS_OVERLAPPED,
  36.                 CW_USEDEFAULT, 0,        /* Use default X, Y            */
  37.                 CW_USEDEFAULT, 0,        /* Use default X, Y            */
  38.                 NULL,                    /* Parent window's handle      */
  39.                 NULL,                    /* Default to Class Menu       */
  40.                 hInst,                   /* Instance of window          */
  41.                 NULL);                   /* Create struct for WM_CREATE */
  42.  
  43.  
  44.  if(hWndMain == NULL)
  45.    {
  46.     LoadString(hInst, IDS_ERR_CREATE_WINDOW, szString, sizeof(szString));
  47.     MessageBox(NULL, szString, NULL, MB_ICONEXCLAMATION);
  48.     return IDS_ERR_CREATE_WINDOW;
  49.    }
  50.  
  51.  ShowWindow(hWndMain, nCmdShow);            /* display main window      */
  52.  
  53.  while(GetMessage(&msg, NULL, 0, 0))        /* Until WM_QUIT message    */
  54.    {
  55.     TranslateMessage(&msg);
  56.     DispatchMessage(&msg);
  57.    }
  58.  
  59.  /* Do clean up before exiting from the application                     */
  60.  CwUnRegisterClasses();
  61.  return msg.wParam;
  62. }
  63.  
  64.  
  65. LONG FAR PASCAL WndProc(HWND hWnd, UINT Message, WPARAM wParam, LPARAM lParam)
  66. {
  67.  HMENU      hMenu=0;            /* handle for the menu                 */
  68.  HDC        hDC;                /* handle for the display device       */
  69.  PAINTSTRUCT ps;                /* holds PAINT information             */
  70.  int        nRc=0;              /* return code                         */
  71.  
  72.  switch (Message)
  73.    {
  74.     case WM_COMMAND:
  75.          switch (wParam)
  76.            {
  77.             case IDM_DIALOG:
  78.                  /* Place User Code to respond to the                   */
  79.                  /* Menu Item Named "Dialog" here.                      */
  80.  
  81.  
  82.                  {
  83.                   FARPROC lpfnDIALOGSMsgProc;
  84.  
  85.                   lpfnDIALOGSMsgProc = MakeProcInstance((FARPROC)DIALOGSMsgProc, hInst);
  86.                   nRc = DialogBox(hInst, MAKEINTRESOURCE(100), hWnd, lpfnDIALOGSMsgProc);
  87.                   FreeProcInstance(lpfnDIALOGSMsgProc);
  88.                  }
  89.                  break;
  90.  
  91.             default:
  92.                 return DefWindowProc(hWnd, Message, wParam, lParam);
  93.            }
  94.          break;        /* End of WM_COMMAND                             */
  95.  
  96.     case WM_CREATE:
  97.              hVlbLib = LoadLibrary("vlist.dll");
  98.          break;       /*  End of WM_CREATE                              */
  99.  
  100.     case WM_DESTROY:
  101.              FreeLibrary(hVlbLib);
  102.          break;
  103.  
  104.    // case WM_PAINT:    /* code for the window's client area              */
  105.    //       /* Obtain a handle to the device context                       */
  106.    //       /* BeginPaint will sends WM_ERASEBKGND if appropriate          */
  107.    //       memset(&ps, 0x00, sizeof(PAINTSTRUCT));
  108.    //       hDC = BeginPaint(hWnd, &ps);
  109.    //
  110.    //       /* Included in case the background is not a pure color         */
  111.    //       SetBkMode(hDC, TRANSPARENT);
  112.    //
  113.    //       /* Inform Windows painting is complete                         */
  114.    //       EndPaint(hWnd, &ps);
  115.    //       break;       /*  End of WM_PAINT                               */
  116.  
  117.     case WM_CLOSE:  /* close the window                                 */
  118.          /* Destroy child windows, modeless dialogs, then, this window  */
  119.          DestroyWindow(hWnd);
  120.          if (hWnd == hWndMain)
  121.            PostQuitMessage(0);  /* Quit the application                 */
  122.         break;
  123.  
  124.     default:
  125.          return DefWindowProc(hWnd, Message, wParam, lParam);
  126.    }
  127.  return 0L;
  128. }
  129.  
  130.  
  131. BOOL FAR PASCAL DIALOGSMsgProc(HWND hWndDlg, UINT Message, WPARAM wParam, LPARAM lParam)
  132. {
  133.  int i,j;
  134.  HWND                   hwndList;
  135.  static char            szText[128];
  136.  LPVLBSTRUCT            lpvlbInStruct;
  137.  
  138.  switch(Message)
  139.    {
  140.     case WM_INITDIALOG:
  141.          cwCenter(hWndDlg, 0);
  142.          /* initialize working variables                                */
  143.          hwndList = GetDlgItem(hWndDlg, 101);
  144.          SendMessage(hwndList, VLB_INITIALIZE, 0, 0L);
  145.          break; /* End of WM_INITDIALOG                                 */
  146.  
  147.     case WM_CLOSE:
  148.          /* Closing the Dialog behaves the same as Cancel               */
  149.          PostMessage(hWndDlg, WM_COMMAND, IDCANCEL, 0L);
  150.          break; /* End of WM_CLOSE                                      */
  151.  
  152.     case WM_COMMAND:
  153.          switch(wParam)
  154.            {
  155.             case IDOK:
  156.                  EndDialog(hWndDlg, FALSE);
  157.                  break;
  158.            }
  159.          break;    /* End of WM_COMMAND                                 */
  160.  
  161.     case VLB_PREV:
  162.          lpvlbInStruct = (LPVLBSTRUCT)lParam;
  163.  
  164.          if ( lpvlbInStruct->lIndex > 0 ) {
  165.             lpvlbInStruct->nStatus = VLB_OK;
  166.             lpvlbInStruct->lIndex--;
  167.             lpvlbInStruct->lData = lpvlbInStruct->lIndex;
  168.             sprintf(szText,"%ld Item",lpvlbInStruct->lIndex);
  169.             lpvlbInStruct->lpTextPointer = szText;
  170.             return TRUE;
  171.          }
  172.          else {
  173.             lpvlbInStruct->nStatus = VLB_ENDOFFILE;
  174.             return TRUE;
  175.          }
  176.          break;
  177.  
  178.     case VLB_FINDPOS:
  179.          lpvlbInStruct = (LPVLBSTRUCT)lParam;
  180.  
  181.          if ( lpvlbInStruct->lIndex == 0L ) {
  182.             goto First;
  183.          }
  184.          else if ( lpvlbInStruct->lIndex == 100L ) {
  185.             goto Last;
  186.          }
  187.          else {
  188.             lpvlbInStruct->lIndex = lpvlbInStruct->lData*1000L;
  189.             lpvlbInStruct->nStatus = VLB_OK;
  190.             sprintf(szText,"%ld Item",lpvlbInStruct->lIndex);
  191.             lpvlbInStruct->lpTextPointer = szText;
  192.             return TRUE;
  193.          }
  194.        break;
  195.  
  196.     case VLB_FINDITEM:
  197.          lpvlbInStruct = (LPVLBSTRUCT)lParam;
  198.  
  199.          lpvlbInStruct->lIndex = lpvlbInStruct->lData;
  200.          lpvlbInStruct->nStatus = VLB_OK;
  201.          sprintf(szText,"%ld Item",lpvlbInStruct->lIndex);
  202.          lpvlbInStruct->lpTextPointer = szText;
  203.  
  204.          return TRUE;
  205.  
  206.        break;
  207.  
  208.     case VLB_FINDSTRING:
  209.     case VLB_FINDSTRINGEXACT:
  210.     case VLB_SELECTSTRING:
  211.        {
  212.          _fstrcpy(szText,lpvlbInStruct->lpFindString);
  213.          lpvlbInStruct->lIndex = atol(szText);
  214.          sprintf(szText,"%ld Item",lpvlbInStruct->lIndex);
  215.          lpvlbInStruct->lpTextPointer = szText;
  216.          lpvlbInStruct->lData = lpvlbInStruct->lIndex;
  217.          lpvlbInStruct->nStatus = VLB_OK;
  218.          return TRUE;
  219.        }
  220.        break;
  221.  
  222.     case VLB_RANGE:
  223.          lpvlbInStruct = (LPVLBSTRUCT)lParam;
  224.  
  225.          lpvlbInStruct->lIndex = 100000L;
  226.          lpvlbInStruct->nStatus = VLB_OK;
  227.          return TRUE;
  228.  
  229.        break;
  230.  
  231.     case VLB_NEXT:
  232.          lpvlbInStruct = (LPVLBSTRUCT)lParam;
  233.  
  234.          if ( lpvlbInStruct->lIndex < 99999L ) {
  235.             lpvlbInStruct->nStatus = VLB_OK;
  236.             lpvlbInStruct->lIndex++;
  237.             lpvlbInStruct->lData = lpvlbInStruct->lIndex;
  238.             sprintf(szText,"%ld Item",lpvlbInStruct->lIndex);
  239.             lpvlbInStruct->lpTextPointer = szText;
  240.             return TRUE;
  241.          }
  242.          else {
  243.             lpvlbInStruct->nStatus = VLB_ENDOFFILE;
  244.             return TRUE;
  245.          }
  246.        break;
  247.  
  248.     case VLB_FIRST:
  249. First:
  250.          lpvlbInStruct = (LPVLBSTRUCT)lParam;
  251.  
  252.          lpvlbInStruct->nStatus = VLB_OK;
  253.          lpvlbInStruct->lIndex = 0L;
  254.          sprintf(szText,"%ld Item",lpvlbInStruct->lIndex);
  255.          lpvlbInStruct->lpTextPointer = szText;
  256.          lpvlbInStruct->lData = lpvlbInStruct->lIndex;
  257.          return TRUE;
  258.  
  259.     case VLB_LAST:
  260. Last:
  261.          lpvlbInStruct = (LPVLBSTRUCT)lParam;
  262.  
  263.          lpvlbInStruct->nStatus = VLB_OK;
  264.          lpvlbInStruct->lIndex = 99999L;
  265.          sprintf(szText,"%ld Item",lpvlbInStruct->lIndex);
  266.          lpvlbInStruct->lpTextPointer = szText;
  267.          lpvlbInStruct->lData = lpvlbInStruct->lIndex;
  268.          return TRUE;
  269.  
  270.        break;
  271.  
  272.     case VLB_GETITEMDATA:
  273.          lpvlbInStruct = (LPVLBSTRUCT)lParam;
  274.  
  275.          lpvlbInStruct->nStatus = VLB_OK;
  276.          lpvlbInStruct->lData = lpvlbInStruct->lIndex;
  277.          return TRUE;
  278.        break;
  279.  
  280.     default:
  281.         return FALSE;
  282.    }
  283.  return TRUE;
  284. }
  285.  
  286.  
  287. int nCwRegisterClasses(void)
  288. {
  289.  WNDCLASS   wndclass;    /* struct to define a window class             */
  290.  memset(&wndclass, 0x00, sizeof(WNDCLASS));
  291.  
  292.  
  293.  /* load WNDCLASS with window's characteristics                         */
  294.  wndclass.style = CS_HREDRAW | CS_VREDRAW | CS_BYTEALIGNWINDOW;
  295.  wndclass.lpfnWndProc = WndProc;
  296.  /* Extra storage for Class and Window objects                          */
  297.  wndclass.cbClsExtra = 0;
  298.  wndclass.cbWndExtra = 0;
  299.  wndclass.hInstance = hInst;
  300.  wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
  301.  wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
  302.  /* Create brush for erasing background                                 */
  303.  wndclass.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
  304.  wndclass.lpszMenuName = szAppName;   /* Menu Name is App Name */
  305.  wndclass.lpszClassName = szAppName; /* Class Name is App Name */
  306.  if(!RegisterClass(&wndclass))
  307.    return -1;
  308.  
  309.  
  310.  return(0);
  311. }
  312.  
  313. void cwCenter(hWnd, top)
  314. HWND hWnd;
  315. int top;
  316. {
  317.  POINT      pt;
  318.  RECT       swp;
  319.  RECT       rParent;
  320.  int        iwidth;
  321.  int        iheight;
  322.  
  323.  /* get the rectangles for the parent and the child                     */
  324.  GetWindowRect(hWnd, &swp);
  325.  GetClientRect(hWndMain, &rParent);
  326.  
  327.  /* calculate the height and width for MoveWindow                       */
  328.  iwidth = swp.right - swp.left;
  329.  iheight = swp.bottom - swp.top;
  330.  
  331.  /* find the center point and convert to screen coordinates             */
  332.  pt.x = (rParent.right - rParent.left) / 2;
  333.  pt.y = (rParent.bottom - rParent.top) / 2;
  334.  ClientToScreen(hWndMain, &pt);
  335.  
  336.  /* calculate the new x, y starting point                               */
  337.  pt.x = pt.x - (iwidth / 2);
  338.  pt.y = pt.y - (iheight / 2);
  339.  
  340.  /* top will adjust the window position, up or down                     */
  341.  if(top)
  342.    pt.y = pt.y + top;
  343.  
  344.  /* move the window                                                     */
  345.  MoveWindow(hWnd, pt.x, pt.y, iwidth, iheight, FALSE);
  346. }
  347.  
  348. void CwUnRegisterClasses(void)
  349. {
  350.  WNDCLASS   wndclass;    /* struct to define a window class             */
  351.  memset(&wndclass, 0x00, sizeof(WNDCLASS));
  352.  
  353.  UnregisterClass(szAppName, hInst);
  354. }
  355.